/*
 * @Author: soso
 * @Date: 2022-02-15 02:00:03
 * @LastEditTime: 2022-03-14 15:26:06
 * @LastEditors: Please set LastEditors
 * @Description: 定义
 * @FilePath: /gomeshsync/core/cfiles/defines.go
 */
package cfiles

import (
	"gomeshsync/cfile"
	"path/filepath"
	"time"

	"gitee.com/kimsoso/go-utils/utils"
)

var (
	ExecPath = utils.GetCurrentAbPath()

	//Asia/Shanghai
	Location = time.FixedZone("CST", 8*60*60)

	// pathOfCloneDirs     = "cmds/dirs.bin"
	// pathOfCloneMainCmds = "cmds/.cmds.bin"
	// pathOfCloneArchCmds = "cmds/.arch.bin"

	pathOfCmds    = filepath.Join(ExecPath, "cmds/cmds.bin")
	pathOfTmpCmds = filepath.Join(ExecPath, "cmds/tcmds.bin")
	PathOfArch    = filepath.Join(ExecPath, "cmds/arch.bin")
	// 无用的，只为满足参数
	PathOfEmptyArch = filepath.Join(ExecPath, "cmds/tarch.bin")
)

var (
	// 线程阻塞通道
	ChanStockCmds chan bool = make(chan bool)

	// 远程目录结构存储
	// svrAllFiles *sofile.Blockfile

	MainCmds *cfile.Cmdfile
	TempCmds *cfile.Cmdfile

	// 系统主命令定义
	// _CMDS = Cmds{
	// 	cmds:     &scmd.MCommands{},
	// 	hidfiles: &scmd.MCommands{},
	// }

	// 临时命令定义
	// _TmpCmds = scmd.NewTempcmds(pathOfTmpCmds)
)

func init() {
	// 关闭通道，放开线程执行
	close(ChanStockCmds)

	// 主命令
	MainCmds = cfile.NewCmdfile(pathOfCmds, PathOfArch)
	// 临时命令
	TempCmds = cfile.NewCmdfile(pathOfTmpCmds, PathOfEmptyArch)
}

// 下载全部文件的结构定义
type Dfile struct {
	IsDir     bool   `yaml:"isDir"`
	FileName  string `yaml:"fileName"`
	FilePath  string `yaml:"filePath"`
	FileSize  int64  `yaml:"fileSize"`
	FileMask  string `yaml:"fileMask"`
	BlockSize int64  `yaml:"blockSize"`
	Done      bool   `yaml:"done"`
}

/**
 * 文件块定义
 */
type CBlock struct {
	seq      int
	offset   int64
	size     int64
	filePath string
}

/**
 * @description: 上传文件临时命令(与上传文件同名，后缀不同)
 * @param {*}
 * @return {*}
 */
type UCommand struct {
	Cmd        int   `yaml:"cmd"`
	CreateTime int64 `yaml:"createTime"`
	DoneTime   int64 `yaml:"doneTime"`
	Done       bool  `yaml:"done"`
}

type Ufile struct {
	Path     string `yaml:"pt"`
	FileType uint8  `yaml:"ft"`
	FileMd5  string `yaml:"md5"`
	FileSize int64  `yaml:"sz"`
}
